package com.itheima.d3_traversal;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.function.Consumer;

public class Test2 {
    public static void main(String[] args) {
        // 一定要注意 s1存储的是地址
        Student s1 = new Student("pxf");
        Student s2 = new Student("rs");
        Collection<Student> students = new ArrayList<>();
        students.add(s1);
        students.add(s2);
        // 三种遍历方式
        //1 iterator
        Iterator<Student> it = students.iterator();
        while(it.hasNext()){
            Student next = it.next();
            System.out.println(next);
        }
        //2 for增强
        System.out.println("=========");
        for(Student student : students){
            System.out.println(student);
        }
        //3 lambda
        System.out.println("========");
        students.forEach((student) -> {
            System.out.println(student);
            });

    }
}
class Student{
    private String name;

    public Student(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                '}';
    }
}
